<!DOCTYPE html>
<html>
<head>
    <title>添加目录</title>
    <include file='public/head'>
	<style>
		.layui-legend-size{font-size:14px !important;}
		.layui-nopadding{padding:0 !important;}
		.layui-overflow{overflow:auto;}
		.layui-nomargin{margin: 0 !important;}
		.layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}
		.layui-input{height:30px !important; }
		.layui-form-search-item .layui-inline{margin-bottom: 5px;} 
		.layui-form-search-item label{margin-left: 15px;}
		.layui-table-page {padding: 7px 0px 0px;}
		.layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}
	</style>
</head>
<body>
<form class="layui-form" action="">
	<table class="layui-table layui-nomargin">
		<!-- 表格内容输出 -->
		<tbody>
			<tr>
				<td>目录名：</td>
				<td><input type="text" class="layui-input" name="file_name" id="file_name" placeholder="目录名" autocomplete="off"></td>
			</tr>
			<tr>
				<td>上级目录：</td>
				<td style = "text-align:left">
			        <select name="modules" lay-filter="list" lay-verify="required" lay-search="" id="parent" name="parent">
			          <option value="">直接选择或搜索选择</option>
			          {$select}
			        </select>	
				</td>
			</tr>
			<tr>
				<td>是否私有：</td>	
				<td width="20%">
				    <div class="layui-input-block" class="layui-input-inline"> 
				      <input type="checkbox" name="switch" id="switch" lay-filter="change" lay-skin="switch" class="layui-input-inline">
				      <div id="tx" class="layui-input-inline"></div>
				    </div>				
				</td>
			</tr>
			<tr>
			<td width="20%">
				指定人员查看:
			</td>
			<td>
				<div class="layui-input-inline" id="tshow" style="display: none;">
					<div id="users" name="users" class="layui-input-inline">
					</div>
					<i class="layui-icon layui-icon-user layui-input-inline" style="font-size: 30px;" onclick="userList()"></i>
				</div>
			</td>	
			</tr>
		</tbody>
	</table>
</form>	


	<include file='public/scripts'>

<script type="text/javascript">

	layui.use('layedit', function(){
	  var layedit = layui.layedit;
	  layedit.build('demo'); //建立编辑器
	});

	    var form = layui.form;

		form.on('select(list)', function(data){
            let selectText=data.elem[data.elem.selectedIndex].text;//得到被选中的文本值
            // selectText=selectText.trim();//去掉&nbap
            selectText=selectText.replace(/\s+/g, "");
            data.elem[data.elem.selectedIndex].text=selectText;//覆盖原文本值
            checkParent();
        });	

		//点击切换
	    form.on('switch(change)',function(){
			$('#tshow').toggle();
			if(private == 0){
				private = 1;
			}else if(private == 1){
				private = 0;
			}
	    }); 

	    //检查父类
	    function checkParent(){
    		let data = {};
    		data['id'] = $('#parent').val();
    		if(data['id']){
				$.ajax({
					url:"{:cmf_plugin_url('Word://admin_index/checkParent')}",
					data:data,
					type:"post",
					//得到选中的内容
					success:function(data){
						//父级私有
						if(data == 1){
							$('#switch').prop('checked','true');
							$('#switch').prop('disabled','true');
							$('#tshow').show();
							$('#tx').html('当前目录不可公开');
							private = 1;
						//父级公开
						}else{
							$('#switch').removeAttr('checked');
							$('#switch').removeAttr('disabled');
							$('#tshow').hide();
							$('#tx').html('');
							private = 0;
						}
						form.render();
					},
					error:function(data){
						layer.msg('查询失败');
						return false;
					}
				})		
    		}
	    }       

		//获取选择值
		function callbackdata(){
			var content = {};
			if($('#file_name').val() == ''){
				layer.msg('请输入文件名');
				return false;
			}
			content['name'] = $('#file_name').val();
			content['parent_id'] = $('#parent').val();
			content['vid'] = vid;
			content['private'] = private;
			return content;
		}

		var vname = [];
		var vid = [];
		var private = 0;
		//用户列表
		function userList(){
				let url = "{:cmf_plugin_url('Word://admin_index/userList')}?&vid="+vid;
				layer.open({
					type: 2//基本层类型  0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
					,title: '用户列表'//层的标题
					,shadeClose: true//是否点击遮罩关闭
					,shade: 0.8//遮罩
					,area: ['500px', '500px']//宽高
					,btn:['提交','关闭']//弹框按钮
					,fixed:false//固定
					,content: url //iframe的url
					,yes:function(index, layero){
						//调用子页面方法得到返回值
						parentInfo = window["layui-layer-iframe" + index].callbackdata(index);
						vname = parentInfo['vname'];
						vid = parentInfo['vid'];
						$('#users').html(vname.join(','));
						layer.closeAll();
						if(parentInfo == false){
							return false;
						}
					}
					,btn2:function(index, layero){
					}
				});
		}

</script>

</body>
</html>